import router from './router'
import store from './store'
import { Message } from 'element-ui'
import { getToken } from '@/utils/auth' // 验权(从cookie中获取)
const whiteList = ['/login'] // 不重定向白名单

router.beforeEach((to, from, next) => {
    if(getToken('Token')) {
        if(to.path === '/login') {
            next({ path: '/' })  
        } else {
            next()
            
        }
    } else {
        if (whiteList.indexOf(to.path) !== -1) {
             // 点击退出时,会定位到这里
             next()
        } else {
            next('/login')
        }
        
    }
})

router.afterEach((to, from) => {
    if(to.path != '/login') {
        store.commit("ADD_TAGS", {path: to.fullPath, title: to.meta.title})
        store.commit('SET_CURRENT_TAGS', {path: to.fullPath, title: to.meta.title})
    }
})